package com.canal.admin.controller;

import com.canal.admin.exception.BuzException;
import com.canal.admin.response.Result;
import com.canal.admin.response.ResultUtil;
import com.canal.admin.service.RtDataService;
import com.canal.admin.transfer.req.data.RtConvertConditions;
import com.canal.admin.transfer.req.data.RtDataConditions;
import com.canal.admin.transfer.req.data.RtDataDetailConditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 实时数据统计
 * @author yangbo
 * @date 2020-07-14 9:15
 */
@RestController
public class RealTimeDataController extends BaseController {

    @Autowired
    private RtDataService rtDataService;

    /**
     * 渠道实时统计数据
     * @param conditions
     * @return
     * @throws BuzException
     */
    @PostMapping(value = "/rt/data/list")
    @PreAuthorize("isAuthenticated()")
    public Result rtDataList(@RequestBody RtDataConditions conditions) throws BuzException {
        return ResultUtil.makeSuccess(rtDataService.rtDataList(conditions));
    }

    /**
     * 一个ip的访问明细
     * @param conditions
     * @param bindingResult
     * @return
     * @throws BuzException
     */
    @PostMapping(value = "/rt/data/detail")
    @PreAuthorize("isAuthenticated()")
    public Result rtDetailList(@RequestBody @Validated RtDataDetailConditions conditions,
                               BindingResult bindingResult) throws BuzException {
        dealReqInvalidError(bindingResult);
        return ResultUtil.makeSuccess(rtDataService.rtDetailList(conditions));
    }

    /**
     * 实时转换数据
     * @param conditions
     * @return
     * @throws BuzException
     */
    @PostMapping(value = "/rt/data/convert/list")
    @PreAuthorize("isAuthenticated()")
    public Result rtConvertDataList(@RequestBody RtConvertConditions conditions) throws BuzException {
        return ResultUtil.makeSuccess(rtDataService.rtConvertList(conditions));
    }
}
